{{ template "base_login.html"}}
{{define "title"}}
    修改密码
{{end}}

{{define "head"}}{{end}}

{{define "li"}}
    <li class="layui-nav-item">
        <a href="/index ">返回首页</a>
    </li>
{{end}}

{{define "content"}}
    <div class="layui-body" style="padding: 15px">
        <form class="layui-form layui-form-pane1" action="" lay-filter="first">
            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-inline" style="width: 50%">
                    <input type="password" name="old_password" lay-verify="required" lay-reqText="请输入您现在的密码" required placeholder="请输入您现在的密码" autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux" style="color: #FF5722">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline" style="width: 50%">
                    <input type="password" name="new_password" lay-verify="required" lay-reqText="请输入您要改的密码" required placeholder="请输入您现在的密码" autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux" style="color: #FF5722">*</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重复新密码</label>
                <div class="layui-input-inline" style="width: 50%">
                    <input type="password" lay-verify="check" lay-reqText="重复密码需要一致" required placeholder="请重复您要改的密码" autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux" style="color: #FF5722">*</div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit type="button">修改密码</button>
                </div>
            </div>
        </form>
    </div>
{{end}}

{{define "script"}}
    <script>
        layui.use(['form', 'element', 'jquery'], function(rewq){
            var form = layui.form,
                $ = layui.jquery;

            form.verify({
                check: function(value){
                    if($('input[name=new_password]').val() !== value){
                        return '两次密码输入不一致！';
                    }
                }
            });
            //监听提交
            form.on('submit', function(data){
                form_data = data.field;
                $.ajax({
                    url:"/api/change_password ",
                    type:"POST",   //请求类型 ,
                    async:false,
                    data: form_data,
                    success:function (res) {
                        if(res.code === "200"){
                            alert("修改密码成功！");
                            location.href = "/login ";
                            return false
                        }
                        else{
                            alert(res.msg);
                        }
                    },
                    error:function f(res) {
                        alert("请求失败！状态码：" + res.status);
                    },
                })
                return false;
            });

        });
    </script>
{{ end }}